package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* ThreeCircleOverlappingView
* */
class ThreeCircleOverlappingView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_80D8FF)
        }
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            save()
            translate(cx, cy + (cy - cy / 2 * 9 / 10 - cy / 10) / 2)

            val mStrokeWidth = (cx / 12).coerceAtLeast(minStrokeWidth)
            mPaint0.strokeWidth = mStrokeWidth

            drawArc(
                -cx / 2 * 9 / 10,
                -cy * 9 / 10,
                cx / 2 * 9 / 10,
                0F,
                90F,
                270F,
                false,
                mPaint0
            )

            drawArc(
                -cx * 9 / 10,
                -cy / 2 * 9 / 10,
                0F,
                cy / 2 * 9 / 10,
                0F,
                270F,
                false,
                mPaint0
            )

            drawArc(
                0F,
                -cy / 2 * 9 / 10,
                cx * 9 / 10,
                cy / 2 * 9 / 10,
                0F,
                360F,
                false,
                mPaint0
            )

            restore()
        }
    }
}